<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Novi test
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">
        function nextOrBack(attr){
            var jedno, drugo, trece;
            if(attr == 0){
                jedno = 'test';
                drugo = 'kontrole'
                trece = 'pop';
            } else if(attr == 1) {
                jedno = 'kontrole';
                drugo = 'pop';
                trece = 'test';
            } else if(attr == 2) {
                jedno = 'test';
                drugo = 'pop';
                trece = 'kontrole';
            }
            document.getElementById(jedno).style.visibility="hidden";
            document.getElementById(jedno).style.zIndex=-1;
            document.getElementById(drugo).style.visibility="hidden";
            document.getElementById(drugo).style.zIndex=-1;
            document.getElementById(trece).style.visibility="visible";
            document.getElementById(trece).style.zIndex=2;
    }
var broj = 0;
var idElementa = 0;
var limit = 3;


function dodajKontrolu(){
    var newRow = document.all("tblKontrole").insertRow();
    newRow.width = "100%";
    var form = document.getElementById("pocetnaForma");
    
     if (broj == limit)  {
          alert("Moguce je napraviti samo " + broj + " kontrole.");
     } else {
        var oCell = newRow.insertCell();
        oCell.width = "8%";
        oCell.innerHTML = " <input type='button' value='X' onclick='makniKontrolu(this);'/>";
        
        oCell = newRow.insertCell();
        oCell.width = "21%";
        oCell.innerHTML = document.getElementById('oceStDev').value + 
            "  <input type='hidden' name='k3k"+idElementa +"' value='"+ document.getElementById('oceStDev').value +"'>";
        
        oCell = newRow.insertCell();
        oCell.width = "21%";
        oCell.innerHTML = document.getElementById('dopStDev').value + 
            "  <input type='hidden' name='k2k"+idElementa+"' value='"+ document.getElementById('dopStDev').value +"'>";
            
        oCell = newRow.insertCell();
        oCell.width = "21%";
        oCell.innerHTML = document.getElementById('kontRizik').value + 
            "  <input type='hidden' name='k1k"+idElementa+"' value='"+ document.getElementById('kontRizik').value +"'>";
        
        oCell = newRow.insertCell();
        oCell.width = "29%";
        oCell.innerHTML = document.getElementById('opisKontrole').value + 
            "  <input type='hidden' name='k0k"+idElementa+"' value='"+ document.getElementById('opisKontrole').value +"'>";
            
        broj = broj + 1;
        idElementa = idElementa + 1;
     }

    
    
     
}
function makniKontrolu(src){
 /* src refers to the input button that was clicked. 
       to get a reference to the containing <tr> element,
       get the parent of the parent (in this case <tr>)
    */   
    var oRow = src.parentElement.parentElement;  
    
    //once the row reference is obtained, delete it passing in its rowIndex   

    document.all("tblKontrole").deleteRow(oRow.rowIndex);  
    broj = broj - 1;
}
$(document).ready(function(){$('#datum').datepicker();});
        
    </script>

    <script type="text/javascript" src="/../../Scripts/jquery-1.4.1.js"></script>

    <script type="text/javascript" src="/../../Scripts/jquery.ui.core.js"></script>

    <script type="text/javascript" src="/../../Scripts/jquery.ui.datepicker.js"></script>

    <form id="pocetnaForma" runat="server">
    <% using (Html.BeginForm("Create", "TestKontrole", FormMethod.Post)) {%>
    <div style="height: 576px">
        <div id="test" style="visibility: visible; z-index: 2; position: absolute">
            <fieldset>
                <legend>Testiranje</legend>
                <p>
                    <label for="datum">
                        Datum:</label>
                    <%= Html.TextBox("datum",DateTime.Now) %>
                    <label for="poduzece">
                        Naziv poduzeca</label>
                    <%= Html.DropDownList("poduzece", (IEnumerable<SelectListItem>)ViewData["klijenti"]) %>
                    <label for="cilj">
                        Opis cilja testiranja:</label>
                    <%= Html.TextArea("cilj", "Test", 5, 40, null)%>
                    <%= Html.ValidationMessage("cilj", "*") %>
                    <label for="jedinica">
                        Opis jedinice uzorka:</label>
                    <%= Html.TextArea("jedinica", "TestJed", 5, 40, null)%>
                    <%= Html.ValidationMessage("jedinica", "*") %>
                </p>
                <p>
                    <input id="nextF" type="button" value="Dalje" onclick="nextOrBack(0)" />
                </p>
            </fieldset>
        </div>
        <div id="pop" style="visibility: hidden; z-index: -1; position: absolute">
            <fieldset>
                <legend>Populacija</legend>
                <p>
                    <label for="opisPop">
                        Opis populacije:</label>
                    <%= Html.TextArea("opisPop", "TestPop", 5, 40, null)%>
                    <%= Html.ValidationMessage("opisPop", "*") %>
                    <label for="populacija">
                        Kriterij populacije</label>
                    <%= Html.TextBox("populacija", DateTime.Now) %>
                    <p>
                        <input id="backF" type="button" value="Natrag" onclick="nextOrBack(1)" />
                        <input id="nextS" type="button" value="Dalje" onclick="nextOrBack(2)" />
                    </p>
            </fieldset>
        </div>
        <div id="kontrole" style="visibility: hidden; z-index: -1; position: absolute">
            <fieldset>
                <legend>Kontrole</legend>
                <p>
                    <label for="opisKontrole">
                        Opis kontrole:</label>
                    <%= Html.TextArea("opisKontrole", "TestKOnt", 5, 40, null)%>
                    <%= Html.ValidationMessage("opisKontrole", "*") %>
                    <label for="kontRizik">
                        Kontrolni rizik (%):</label>
                    <%= Html.TextBox("kontRizik",5)%>
                    <%= Html.ValidationMessage("kontRizik", "*")%>
                    <label for="dopStDev">
                        Dopustiva stopa devijacije (%):</label>
                    <%= Html.TextBox("dopStDev",5)%>
                    <%= Html.ValidationMessage("dopStDev", "*")%>
                    <label for="oceStDev">
                        Ocekivana stopa devijacije (%):</label>
                    <%= Html.TextBox("oceStDev",1)%>
                    <%= Html.ValidationMessage("oceStDev", "*")%>
                </p>
                <p>
                    <input id="Button1" style="azimuth: right" type="button" value="Dodaj kontrolu" onclick="dodajKontrolu()" />
                </p>
                <div id="pKont">
                    <table  border="0" width="100%" cellpadding="0" cellspacing="0" class="data-table">
                        <tr>
                            <td width="29%">
                                <label>
                                    Opis kontrole</label>
                            </td>
                            <td width="21%">
                                <label>
                                    Kontrolni rizik</label>
                            </td>
                            <td width="21%">
                                <label>
                                    Doputiva stopa devijacije</label>
                            </td>
                            <td width="21%">
                                <label>
                                    Ocekivana stopa devijacije</label>
                            </td>
                            <td width="8%">
                                <label> Ukloni kontrolu
                                </label>
                            </td>
                        </tr>
                        <tr>
                        <td colspan = "5" style="border-bottom-width:thin; padding:0,0,0,0;">
                            <table id="tblKontrole" border="0" width="100%" cellpadding="0" cellspacing="0" class="data-table">
                                
                            </table>
                        </td>
                        </tr>
                    </table>
                </div>
                <p></p>
                <p></p>
                <p>
                    <input id="backS" type="button" value="Natrag" onclick="nextOrBack(0)" />
                </p>
                <p>
                    <input type="submit" value="Izracunaj" />
                </p>
            </fieldset>
        </div>
    </div>
    <% } %>
    <div>
        <%=Html.ActionLink("Back to List", "Index") %>
    </div>
    <hr />
    </form>
</asp:Content>
